<template>
	<div style="text-align: center;margin-top: 15vh;">
		<van-icon name="gold-coin" color="gold" size="10vh" />
		<div style="margin-top: 3vh;font-size: 2vh;">我的钱包</div>
		<div style="margin-top: 1vh;font-size: 5vh;">
			<strong>
				<span style="margin-right: 2vh;font-size: 2.5vh;">&yen;</span>
				<span>{{moneyShow}}</span>
			</strong>

		</div>
		<van-button type="success" @click="weChatChargePageShow=true"
			style="width: 30vh;height: 5vh;position: absolute;bottom: 20vh;margin-left: -15vh; border-radius: 1vh;">充值</van-button>
		<van-popup  v-model:show="weChatChargePageShow" position="right" :style="{ width: '100%', height: '100%' }" closeable
			close-icon="arrow-left" close-icon-position="top-left" lazy-render>
			<WeChatChargePage :uid="user.id" :close="closeChargePage"></WeChatChargePage>
		</van-popup>
	</div>
</template>

<script>
	import url from '@/assets/url.json';
	import WeChatChargePage from './WeChatChargePage.vue';
	
	export default {
		props:{
			user: Object
		},
		components:{
			WeChatChargePage
		},
		
		mounted() {
			this.money=this.user.money;
			this.flashMoney(this.setMoneyShow(this.changePriceType(this.user.money)));
		},
		data() {
			return {
				money: '',
				moneyShow: '',
				weChatChargePageShow:false,
			}
		},
		methods: {
			flashMoney() {
				this.$axios({
					url: url.ip + '/api-user/user',
					method: 'GET',
					headers: {
						token: this.$cookies.get('token'),
					}
				}).then((res) => {
					if (res.data.code === 0) {
						this.setMoney(res.data.data.money);
						this.setMoneyShow(this.changePriceType(res.data.data.money));
					}
				}).catch((err) => {
					console.log(err);
				})
			},
			setMoney(m){
				this.money=m;
			},
			setMoneyShow(m){
				this.moneyShow=m;
			},
			closeChargePage(){
				this.flashMoney();
				this.weChatChargePageShow=false;
			},
			changePriceType(price) {
				let str = price;
				let numberPrice = Number.parseInt(str);
				if (numberPrice < 10) {
					str = '00' + str;
				} else {
					if (numberPrice < 100) {
						str = '0' + str;
					}
				}
			
				let arr = str.split('');
				arr.splice(-2, 0, '.');
				str = arr.join('');
				return str;
			},
		},
	}
</script>

<style>
</style>